﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Runtime.InteropServices;
using System.Windows.Interop;

// this code is uber messy but at least it works

// in here, (string) put before, say x.SelectedItem is so it works and doesn't throw up a 'possible unintended reference comparison'

namespace KKnWPF
{
	/// <summary>
	/// Interaction logic for MainWindow.xaml
	/// </summary>
	public partial class MainWindow : Window
	{
		public MainWindow()
		{
			this.InitializeComponent();

			// Insert code required on object creation below this point.
		}

        public const int WM_NCLBUTTONDOWN = 0xA1;
        public const int HT_CAPTION = 0x2;

        [DllImportAttribute("user32.dll")]
        public static extern int SendMessage(IntPtr hWnd, int Msg,
                        int wParam, int lParam);

        [DllImportAttribute("user32.dll")]
        public static extern bool ReleaseCapture();

        public void move_window(object sender, MouseButtonEventArgs e)
        {
            ReleaseCapture();
            SendMessage(new WindowInteropHelper(this).Handle,
                    WM_NCLBUTTONDOWN, HT_CAPTION, 0);
        }

        private void clearBuildBox()
        {
            this.build.Items.Clear();
        }
        private void bootDiskI(object sender, RoutedEventArgs e)
        {
            
        }

        private void showAbout(object sender, RoutedEventArgs e)
        {
          Window aboutBox = new About();
          aboutBox.Show();
        }

        private void doExit(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            product.Items.Add(Products.Default.chicago);
            product.Items.Add(Products.Default.memphis);
            product.Items.Add(Products.Default.memphisnt);
            product.Items.Add(Products.Default.me);
            product.Items.Add(Products.Default.whistler);
            product.Items.Add(Products.Default.netserver);
            product.Items.Add(Products.Default.lh);
            product.Items.Add(Products.Default.lhpost);
            product.Items.Add(Products.Default.vista);
            product.Items.Add(Products.Default.seven);
            //product.Items.Add(Products.Default.user);
            product.SelectedItem = "Chicago [Windows 95]";
            //getBuildInfo();
        }

        private void productParse(object sender, SelectionChangedEventArgs e)
        {
            getProductInfo();
        }

        /*private void clearBuildBox
        {
            //does nothing at this moment.
        }*/
        private void getProductInfo()
        {
            //DON'T CALL THIS UNLESS YOU KNOW WHAT YOU'RE DOING!!!
            //IT WILL WRECK THE BUILD COMBOBOX UNLESS CALLED AT THE RIGHT TIME
            //WITH THE BOX CLEAR!!!
            if ((string)product.SelectedItem == "Chicago [Windows 95]")
            {
                clearBuildBox();
                build.Items.Add(chicago.Default.b56);
                build.Items.Add(chicago.Default.b58s);
                build.Items.Add(chicago.Default.b112);
                build.Items.Add(chicago.Default.b189);
                build.Items.Add(chicago.Default.b480);
                build.SelectedItem = "56";
            }
            else if ((string)product.SelectedItem == "Memphis [Windows 98]")
            {
                clearBuildBox();
                build.Items.Add(memphis.Default.b1691);
                build.Items.Add(memphis.Default.b1900);
                build.SelectedItem = "1691";
            }
        }

        private void buildParse(object sender, SelectionChangedEventArgs e)
        {
            getBuildInfo();
        }

        private void getBuildInfo()
        {
            if ((string)build.SelectedItem == "56")
            {
                key.Text = chicago.Default.b56key;
                date.Text = chicago.Default.b56date;
                pass.Text = chicago.Default.b56pass;
                preIns.Text = chicago.Default.b56pre;
            }
            else if ((string)build.SelectedItem == "58s")
            {
                key.Text = chicago.Default.b58skey;
                date.Text = chicago.Default.b58sdate;
                pass.Text = chicago.Default.b58spass;
                preIns.Text = chicago.Default.b58spre;
            }
            else if ((string)build.SelectedItem == "112")
            {
                key.Text = chicago.Default.b112key;
                date.Text = chicago.Default.b112date;
                pass.Text = chicago.Default.b112pass;
                preIns.Text = chicago.Default.b112pre;
            }
            else if ((string)build.SelectedItem == "189")
            {
                key.Text = chicago.Default.b189key;
                date.Text = chicago.Default.b189date;
                pass.Text = chicago.Default.b189pass;
                preIns.Text = chicago.Default.b189pre;
            }
            else if ((string)build.SelectedItem == "480 [German]")
            {
                key.Text = chicago.Default.b480key;
                date.Text = chicago.Default.b480date;
                pass.Text = chicago.Default.b480pass;
                preIns.Text = chicago.Default.b480pre;
            }
            else if ((string)build.SelectedItem == "1691")
            {
                key.Text = memphis.Default.b1691key;
                date.Text = memphis.Default.b1691date;
                pass.Text = memphis.Default.b1691pass;
                preIns.Text = memphis.Default.b1691pre;
            }
            else if ((string)build.SelectedItem == "1900")
            {
                key.Text = memphis.Default.b1900key;
                date.Text = memphis.Default.b1900date;
                pass.Text = memphis.Default.b1900pass;
                preIns.Text = memphis.Default.b1900pre;
            }
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            getBuildInfo();
        }

        private void preIns_MouseDown(object sender, MouseButtonEventArgs e)
        {

        }

        private void button1_Click_1(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

	}
}